package com.czl.module_service.fragment.assetUse

import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.czl.base.base.BaseTabFragment
import com.czl.base.base.BaseTabViewModel
import com.czl.base.config.AppConstants
import com.czl.base.databinding.FragmentBaseTabBinding
import com.czl.base.event.LiveBusCenter
import com.czl.base.route.RouteCenter
import me.yokeyword.fragmentation.SupportFragment

@Route(path = AppConstants.Router.Service.F_SERVICE_ASSET_USAGE)
class AssetUsageFragment : BaseTabFragment<FragmentBaseTabBinding, BaseTabViewModel>() {

    private var applicationType : Int = 0

    override fun initData() {
        super.initData()
        if (applicationType == 0) {
            viewModel.tabData.set("领用申请, 我的申请, 领用审批")
            viewModel.tvTitle.set("资产领用")
        } else {
            viewModel.tabData.set("借用申请, 我的申请, 借用审批")
            viewModel.tvTitle.set("资产借用")
        }
    }

    override fun initViewObservable() {
        super.initViewObservable()
        LiveBusCenter.observeGoToTabEvent(this, {
            binding.viewPager.currentItem = 1
            LiveBusCenter.postAssetResultReturnEvent(1)
        })
    }

    override fun fragments(): List<SupportFragment> {
        applicationType =
            arguments?.getSerializable(AppConstants.BundleKey.USAGE_APPLICATION_TYPE) as Int
        var router2 = AppConstants.Router.Service.F_SERVICE_USAGE_APPLY_ADD
        if (applicationType == 0) {
            router2 = AppConstants.Router.Service.F_SERVICE_USAGE_APPLY_ADD
        } else {
            router2 = AppConstants.Router.Service.F_SERVICE_BORROW_APPLY_ADD
        }
        return arrayListOf(
            RouteCenter.navigate(router2, Bundle().apply {
            }) as SupportFragment,

            RouteCenter.navigate(AppConstants.Router.Service.F_SERVICE_MY_USAGE_APPLY, Bundle().apply {
                putIntegerArrayList(AppConstants.BundleKey.USAGE_TAB_INDEX, arrayListOf<Int>(1, applicationType))
            }) as SupportFragment,

            RouteCenter.navigate(AppConstants.Router.Service.F_SERVICE_MY_USAGE_APPLY, Bundle().apply {
//                putSerializable(AppConstants.BundleKey.USAGE_TAB_INDEX, 2)
                putIntegerArrayList(AppConstants.BundleKey.USAGE_TAB_INDEX, arrayListOf<Int>(2, applicationType))
            }) as SupportFragment
        )
    }

    override fun useBaseLayout(): Boolean {
        return true
    }
}